package com.hospital.controller;

import com.hospital.domain.DoctorSit;
import com.hospital.domain.Register;
import com.hospital.service.DoctorSitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/doctorSit")
public class DoctorSitController {


    @Autowired
    DoctorSitService doctorSitService;

    @GetMapping("/selectDoctorSit")
    public List<DoctorSit> selectDoctorSit(int doctorID){
        return doctorSitService.selectDoctorSitByUDoctorID(doctorID);
    }

    @PostMapping("/subRemain")
    public int subRemain(@RequestBody DoctorSit doctorSit){
        return doctorSitService.subRemain(doctorSit);
    }

    @PostMapping("/addRemain")
    public int addRemain(@RequestBody Register register, HttpSession session){
        int userID = (int)session.getAttribute("userID");
        register.setUserID(userID);
        System.out.println(register);
        return doctorSitService.addRemain(register);
    }
    @PostMapping("/addDoctorSit")
    public Integer addDoctorSit(@RequestBody DoctorSit doctorSit){
        int doctorID = doctorSit.getDoctorID();
        int sitID = doctorSit.getSitID();
        DoctorSit ds = doctorSitService.selectDoctorSitBySitIDAndDoctorID(doctorID,sitID);
        if(ds != null){
            return null;
        }
        return doctorSitService.addDoctorSit(doctorSit);
    }

    @GetMapping("/selectDocSitName")
    public List<DoctorSit> selectDoctorSitByDoctorName(String doctorName){
        return doctorSitService.selectDoctorSit(doctorName);
    }
}
